package com.bzy.blp.upms.service.impl;


import com.bzy.blp.model.TSystemAppInfoDat;
import com.bzy.blp.upms.mapper.PermissionMapper;
import com.bzy.blp.upms.service.AppService;
import com.bzy.blp.upms.service.PermissionService;
import com.bzy.blp.upms.service.RoleService;
import com.bzy.blp.upms.vo.RoleResourceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    AppService appService;
    @Autowired
    RoleService roleService;
    @Autowired
    PermissionMapper permissionMapper;

    @Override
    public List<RoleResourceVO> findRolePermissionList(Long userId, String appKey) throws Exception {
        List<RoleResourceVO> rolePermissions = null;
        TSystemAppInfoDat appInfo = appService.findAppIdByAppKey(appKey);
        List<Long> roleIds = roleService.findRoleIdListByAppId(appInfo.getAppId());
        rolePermissions = permissionMapper.findRolePermissionList(roleIds);
        if (rolePermissions != null) {
            rolePermissions.forEach(per -> {
                per.setAppName(appInfo.getAppName());
            });
        }
        return rolePermissions;
    }
}
